<template>
    <div>
        <el-card class="!border-none mb-4" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" inline>
                <el-form-item label="订单编号" prop="sn">
                    <el-input class="w-[280px]" v-model="queryParams.sn" clearable placeholder="请输入订单编号" />
                </el-form-item>
                <el-form-item label="商户" prop="merchant_id">
                    <el-input class="w-[280px]" v-model="queryParams.merchant_id" clearable placeholder="请输入商户" />
                </el-form-item>
                <el-form-item label="状态" prop="status">

                    <el-select style="width: 280px" v-model="queryParams.status" value-key="" placeholder="" clearable
                        filterable>
                        <el-option label="全部" value="all"></el-option>
                        <el-option label="待处理" value="0"></el-option>
                        <el-option label="已处理" value="1"></el-option>
                        <el-option label="拒绝" value="-1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input class="w-[280px]" v-model="queryParams.remark" clearable placeholder="请输入备注" />
                </el-form-item>
                <el-form-item label="账号" prop="account">
                    <el-input class="w-[280px]" v-model="queryParams.account" clearable placeholder="请输入账号" />
                </el-form-item>
                <el-form-item label="方式" prop="way">
                    <el-input class="w-[280px]" v-model="queryParams.way" clearable placeholder="请输入方式" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none" v-loading="pager.loading" shadow="never">


            <el-button-group>
                <el-button type="primary" size="default" @click="showWithdrawapply">申请</el-button>
            </el-button-group>




            <div class="mt-4">
                <el-table :data="pager.lists" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55" />
                    <el-table-column label="订单编号" prop="sn" />
                    <el-table-column label="金额" prop="amount" />
                    <el-table-column label="状态" prop="status">
                        <template #default="{ row }">
                            <el-tag v-if="row.status == 1" type="success">已处理</el-tag>
                            <el-tag v-if="row.status == 0" type="info">待处理</el-tag>
                            <el-tag v-if="row.status == -1" type="danger">拒绝</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="备注" prop="remark" />
                    <el-table-column label="账号" prop="account" />
                    <el-table-column label="方式" prop="way" />

                </el-table>
            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>

        <withdrawapply ref="withdrawapplyRef" :dict-data="dictData" @success="getLists" />

    </div>
</template>

<script lang="ts" setup name="withdrawOrderLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'

import { apiWithdrawLists } from '@/api/merchantcenter'

import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'

import withdrawapply from '@/views/merchantcenter/withdrawapply.vue'

const withdrawapplyRef = shallowRef<InstanceType<typeof withdrawapply>>()
const showWithdrawapply = () => {
    withdrawapplyRef.value?.open()
}



// 查询条件
const queryParams = reactive({
    sn: '',
    merchant_id: '',
    status: '',
    remark: '',
    account: '',
    way: ''
})

// 选中数据
const selectData = ref<any[]>([])

// 表格选择后回调事件
const handleSelectionChange = (val: any[]) => {
    selectData.value = val.map(({ id }) => id)
}

// 获取字典数据
const { dictData } = useDictData('')

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiWithdrawLists,
    params: queryParams
})
getLists()
</script>
